#ifndef DRAWROADITEM_H
#define DRAWROADITEM_H

#include <QObject>
#include <QGraphicsPolygonItem>
#include <QDebug>
#include <QPainter>
#include <QGraphicsSceneMouseEvent>
#include "algorithm/spline_curves/splinecurves.h"
#include "road/commondefine.h"

class DrawRoadItem: public QObject, public QGraphicsPolygonItem
{
     Q_OBJECT

public:
    explicit DrawRoadItem(QObject *parent = nullptr);

    virtual ~DrawRoadItem()
    {
    }

    void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = Q_NULLPTR) Q_DECL_OVERRIDE;

    void addPoint(const QPointF &point)
    {
        qDebug() << "Begin addPoint, size is: " << m_qvecRoadPoints.size();
        m_qvecRoadPoints.append(point);
        m_pSplinecurves->addCtrlPoint(point);
        qDebug() << "End addPoint, size is: " << m_qvecRoadPoints.size();
    }

    QPointF getLink() const;

protected:
    void mousePressEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
    void mouseReleaseEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
    void mouseMoveEvent(QGraphicsSceneMouseEvent *event) Q_DECL_OVERRIDE;
    void hoverMoveEvent(QGraphicsSceneHoverEvent *event) Q_DECL_OVERRIDE;

private:
    QVector<QPointF> m_qvecRoadPoints;
    bool m_bStart;

    Splinecurves *m_pSplinecurves;

private:
    std::string getRoadID();
    std::string getRoadName();
    std::string getJunction();
    double getLength();
    RoadLink getRoadLink();
    RoadType getRoadType();
    PlanView getPlanView();
    ElevationProfile getElevationProfile();
    Lanes getLanes();
    Objects getObjects();
    Signals getSignals();
};

#endif // DRAWROADITEM_H
